<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文字覆盖图像悬停</title>
</head>
<body>
<h2>淡入效果</h2>
<p>鼠标移动到图片上查看效果</p>

<div class="container">
    <img src="../img/pineapple.jpg" alt="Avatar" class="image">
    <div class="overlay">
        <div class="text">Hello World</div>
    </div>
</div>

<style>
    .image{
        display: block;

    }
    .container{
        width: 300px;
        height: 300px;
       position: relative;
    }
    .overlay{
        width: 100%;
        height: 100%;
        opacity: 0;
        background: blue;
        position: absolute;
        top:0;
        left:0;

        transition: 1s;

    }
    .text{
        color: white;
        margin: auto;
        position:absolute;
        top:50%;
        left:50%;
        transform: translate(-50%, -50%);
    }
    .container:hover .overlay{
        opacity: 1;
    }






</style>
</body>
</html>